package it.gma.torero.parsing.token;

import it.gma.torero.operand.Operand;
import it.gma.torero.parsing.ExpressionTreeBuilder;
import it.gma.torero.parsing.Tokenizer;
import it.gma.torero.parsing.Tokenizer.MalformedException;
import it.gma.torero.parsing.Tokenizer.ReturnType;

public class Group extends Token  {

	Tokenizer tokenizer;

	Group(String sequence) throws MalformedException {
		super(sequence);
		if ("()".equals(sequence)) {
			tokenizer = new Tokenizer("'true'");
		} else {
			tokenizer = new Tokenizer(sequence.substring(1, sequence.length() - 1));
		}
	}

	public Token getRoot() throws MalformedException {		
		return  ExpressionTreeBuilder.getRoot(tokenizer);
	}

	@Override
	public Token.Type getType() {
		return Type.GROUP;
	}



	@Override
	public ReturnType getReturnType() throws MalformedException {
		return getRoot().getReturnType();
	}

	@Override
	public Operand asOperand() throws MalformedException {
		return ExpressionTreeBuilder.getRoot(tokenizer).asOperand();
	}



}